package cn.com.jslh.boarpro.main.presenter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import net.idik.lib.slimadapter.SlimAdapterEx;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import cn.com.jslh.boarpro.base.mvp.BaseListPresenter;
import cn.com.jslh.boarpro.base.mvp.BaseListView;
import cn.com.jslh.boarpro.main.model.AddBreedingRecordModelImpl;
import cn.com.jslh.boarpro.tables.BreedRecordTable;
import cn.com.jslh.boarpro.util.WebService;
import cn.com.jslh.boarpro.util.database.DataBaseUtil;

/**
 * 作者：周洲 on 2017/7/28 10:40
 * <p>
 * 邮箱：double0zhou@126.com
 */

public class AddBreedingRecordPresenterImpl extends BaseListPresenter {

    private SlimAdapterEx infoAdapter;
    public static JSONArray persons;

    public AddBreedingRecordPresenterImpl(Context context, BaseListView baseListView) {
        super(context, baseListView, new AddBreedingRecordModelImpl(context));
    }

    @Override
    public void upDatas(String... param) {
        //获取配种员信息
        ((AddBreedingRecordModelImpl)baseListModel).asyncGetDatas(new WebService.NetSuccessListener() {
            @Override
            public void Success(String s) throws JSONException {
                JSONObject jsonObject = new JSONObject(s);
                persons= null;
                persons = jsonObject.getJSONArray("array");
            }
        });
    }

    @Override
    public void setUI(RecyclerView recyclerView, String... params) {
    }

    /**
     * 新增记录
     *
     * @param params
     */
    public boolean subBreedingRecordItemInfo(String... params) {
        ArrayList<Object> datas = DataBaseUtil.GetData(context, BreedRecordTable.class, " where muZhuID = '" + params[0] + "'");
        if (datas.size() > 0) {
            Toast.makeText(context, "不能重复提交母猪数据", Toast.LENGTH_SHORT).show();
            return false;
        } else {
            ((AddBreedingRecordModelImpl) baseListModel).save2Db(params);
            baseListView.onItemClicked("记录新增成功");
            return true;
        }
    }
}
